package com.googlecode.yoohoo.xmppcore.protocol.stanza;

import junit.framework.Assert;

import org.junit.Test;

import com.googlecode.yoohoo.xmppcore.protocol.JabberId;
import com.googlecode.yoohoo.xmppcore.protocol.XmlLangText;

public class MessageTest {
	private static final String messageXml =
		"<message type='chat' from='juliet@example.com/balcony' to='romeo@example.net' xml:lang='en'>" +
			"<subject>Hello!</subject>" +
			"<subject xml:lang='zh'>你好！</subject>" +
			"<body>Nice to meet you!</body>" +
			"<body xml:lang='zh'>很高兴能认识你！</body>" +
			"<thread>e0ffe42b28561960c6b12b944a092794b9683a38</thread>" +
		"</message>";
	
	@Test
	public void toXml() {
		Message message = new Message();
		message.setFrom(JabberId.parseJidString("juliet@example.com/balcony"));
		message.setTo(JabberId.parseJidString("romeo@example.net"));
		message.setType("chat");
		message.setXmlLang("en");
		
		message.getSubjects().add(new XmlLangText("Hello!"));
		message.getSubjects().add(new XmlLangText("你好！", "zh"));
		
		message.getBodies().add(new XmlLangText("Nice to meet you!"));
		message.getBodies().add(new XmlLangText("很高兴能认识你！", "zh"));
		
		message.setThread("e0ffe42b28561960c6b12b944a092794b9683a38");
		
		Assert.assertEquals(messageXml, message.toXml());
	}
}
